<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>闭包的使用</title>
  <style>
    * {
      padding: 0;
      margin: 0;
      box-sizing: border-box;
    }

    body {
      position: relative;
    }

    #btn {
      position: absolute;
      top: 0px;
      left: 0px;
    }
  </style>
</head>

<body>
  <button id="btn">快点击我吧</button>
</body>
<script>
  "use strict"; {
    {
      // 复用相同的方法了
      let arr = [1, 23, 123, 44, 89];
      let arr1 = [29, 1234, 345];
      let filters = (a, b) => {
        return value => {
          return a < value && value < b;
        };
      };
      let arrs = arr.filter(filters(10, 50));
      // console.log(`%c${arrs}`,`color: red; font-size: 30px; font-weight: bold; font-family: kaiti`);
    }; {
      // 动画加速的原因
      let lefts = 1;
      let interval = false;
      let btn = document.getElementById("btn");
      btn.addEventListener("click", e => {
        if (!interval) {
          interval = true;
          setInterval(() => {
            btn.style.left = `${lefts++}px`;
          }, 0.1 * 1000);
        };
      });
    }; {
      let obj = {
        name: "cz",
        gets: function () {
          return () => {
            console.log(this.name);
          };
        }
      };
      obj.gets()();
    };
  };
</script>

</html>